package com.yin.good.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.yin.good.entity.GoodInfoDTO;
import com.yin.good.entity.GoodInfoEntity;
import com.yin.good.entity.GoodTypeEntity;
import com.yin.good.jpa.GoodInfoJPA;
import com.yin.good.jpa.GoodTypeJPA;
import com.yin.mapper.GoodInfoMapper;

/**
*@author LSY
*Time: 2018年12月26日下午5:42:30
*
*
*/
@RestController
@RequestMapping("/good")
public class GoodController {
	/**
     * 注入商品基本信息jpa
     */
    @Autowired
    private GoodInfoJPA goodInfoJPA;
    /**
     * 注入商品类型jpa
     */
    @Autowired
    private GoodTypeJPA goodTypeJPA;
    /**
     * 注入mapStruct转换Mapper
     */
    @Autowired
    private GoodInfoMapper goodInfoMapper;

    /**
     * 查询商品详情
     * @param id
     * @return
     */
    @RequestMapping(value = "/detail/{id}")
    public GoodInfoDTO detail(@PathVariable("id") Long id)
    {
        //查询商品基本信息
        GoodInfoEntity goodInfoEntity = goodInfoJPA.getOne(id);
        //查询商品类型基本信息
        GoodTypeEntity typeEntity = goodTypeJPA.getOne(goodInfoEntity.getType().getId());
        //返回转换dto
        return goodInfoMapper.from(goodInfoEntity,typeEntity);
    }

	
}
